vars.insert(it.key(), it.value());
#ifdef Q_OS_UNIX
- const OrderedNameMapMutexLocker locker(this, &other);
auto nit = other.nameMap.constBegin();
const auto nend = other.nameMap.constEnd();
for ( ; nit != nend; ++nit)
return true;
if (d) {
if (other.d) {
+ QProcessEnvironmentPrivate::OrderedMutexLocker locker(d, other.d);
return d->vars == other.d->vars;
} else {
return isEmpty();
{
if (!d)
return false;
+ QProcessEnvironmentPrivate::MutexLocker locker(d);
return d->vars.contains(d->prepareName(name));
}
if (!d)
return defaultValue;
+ QProcessEnvironmentPrivate::MutexLocker locker(d);
const auto it = d->vars.constFind(d->prepareName(name));
if (it == d->vars.constEnd())
return defaultValue;
{
if (!d)
return QStringList();
+ QProcessEnvironmentPrivate::MutexLocker locker(d);
return d->toList();
}
{
if (!d)
return QStringList();
+ QProcessEnvironmentPrivate::MutexLocker locker(d);
return d->keys();
}
return;
// our re-impl of detach() detaches from null
+ QProcessEnvironmentPrivate::MutexLocker locker(e.d);
d->insert(*e.d);
}
inline QString nameToString(const Key &name) const { return name; }
inline Value prepareValue(const QString &value) const { return value; }
inline QString valueToString(const Value &value) const { return value; }
-#else
- struct NameMapMutexLocker : public QMutexLocker
- {
- NameMapMutexLocker(const QProcessEnvironmentPrivate *d) : QMutexLocker(&d->nameMapMutex) {}
+ struct MutexLocker {
+ MutexLocker(const QProcessEnvironmentPrivate *) {}
};
- struct OrderedNameMapMutexLocker : public QOrderedMutexLocker
- {
- OrderedNameMapMutexLocker(const QProcessEnvironmentPrivate *d1,
- const QProcessEnvironmentPrivate *d2)
- : QOrderedMutexLocker(&d1->nameMapMutex, &d2->nameMapMutex)
- {}
+ struct OrderedMutexLocker {
+ OrderedMutexLocker(const QProcessEnvironmentPrivate *,
+ const QProcessEnvironmentPrivate *) {}
};
-
+#else
inline Key prepareName(const QString &name) const
{
- const NameMapMutexLocker locker(this);
Key &ent = nameMap[name];
if (ent.isEmpty())
ent = name.toLocal8Bit();
inline QString nameToString(const Key &name) const
{
const QString sname = QString::fromLocal8Bit(name);
- {
- const NameMapMutexLocker locker(this);
- nameMap[sname] = name;
- }
+ nameMap[sname] = name;
return sname;
}
inline Value prepareValue(const QString &value) const { return Value(value); }
inline QString valueToString(const Value &value) const { return value.string(); }
+ struct MutexLocker : public QMutexLocker
+ {
+ MutexLocker(const QProcessEnvironmentPrivate *d) : QMutexLocker(&d->mutex) {}
+ };
+ struct OrderedMutexLocker : public QOrderedMutexLocker
+ {
+ OrderedMutexLocker(const QProcessEnvironmentPrivate *d1,
+ const QProcessEnvironmentPrivate *d2) :
+ QOrderedMutexLocker(&d1->mutex, &d2->mutex)
+ {}
+ };
+
QProcessEnvironmentPrivate() : QSharedData() {}
QProcessEnvironmentPrivate(const QProcessEnvironmentPrivate &other) :
- QSharedData(), vars(other.vars)
+ QSharedData()
{
+ // This being locked ensures that the functions that only assign
+ // d pointers don't need explicit locking.
// We don't need to lock our own mutex, as this object is new and
// consequently not shared. For the same reason, non-const methods
// do not need a lock, as they detach objects (however, we need to
// ensure that they really detach before using prepareName()).
- NameMapMutexLocker locker(&other);
+ MutexLocker locker(&other);
+ vars = other.vars;
nameMap = other.nameMap;
- // We need to detach our nameMap, so that our mutex can protect it.
- // As we are being detached, it likely would be detached a moment later anyway.
+ // We need to detach our members, so that our mutex can protect them.
+ // As we are being detached, they likely would be detached a moment later anyway.
+ vars.detach();
nameMap.detach();
}
#endif
#ifdef Q_OS_UNIX
typedef QHash<QString, Key> NameHash;
mutable NameHash nameMap;
- mutable QMutex nameMapMutex;
+
+ mutable QMutex mutex;
#endif
static QProcessEnvironment fromList(const QStringList &list);